package lc.util;

//	Utility to efficiently store and grow an array of integers (without boxing)
public final class SimpleIntArray {
	public int[] data;
	public int logicalSize;
	public final void add(int element) {
		maybeExpand();
		data[logicalSize++] = element;
	}
	public final int[] construct() {
		if (data == null) return null;
		int[] ret = new int[logicalSize];
		for (int i = 0, n = logicalSize; i != n; ++i) {
			ret[i] = data[i];
		}
		return ret;
	}
	private final void maybeExpand() {
		if (data == null) {
			data = new int[10];
		}
		else if (logicalSize == data.length) {
			int[] nuData = new int[(int)(data.length * 1.5) + 5];
			for (int i = 0, n = data.length; i < n; ++i) {
				nuData[i] = data[i];
			}
			data = nuData;
		}
	}
}

